package com.zany.children.dao;

import com.zany.children.vo.Student;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class StudentDaoImpl extends SqlMapClientDaoSupport implements StudentDao {
    @Override
    public Integer getStudentListPageCount(Map<String,Object> student) {
        Integer count = (Integer) getSqlMapClientTemplate().queryForObject("student.getStudentListPageCount", student);
        return count;
    }

    @Override
    public List<Student> getStudentListPage(Map<String,Object> student) {
        List list = getSqlMapClientTemplate().queryForList("student.getStudentListPage", student);
        return list;
    }

    @Override
    public Long saveStudent(Student student) {
        Long insert = (Long)getSqlMapClientTemplate().insert("student.insertStudent", student);
        return insert;
    }


    @Override
    public void updateStudent(Student student){
        getSqlMapClientTemplate().update("student.updateStudent",student);
    }


    @Override
    public Student getStudentById(Long id){
        Student student =(Student) getSqlMapClientTemplate().queryForObject("student.getStudentById", id);
        return student;
    }


    @Override
    public void saveClassStuRela(Long classId, Long stuId, String creater) {
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("classId",classId);
        map.put("stuId",stuId);
        map.put("creater",creater);
        getSqlMapClientTemplate().insert("student.saveClassStuRela", map);
    }

    @Override
    public void deleteStudentById(Long stuId) {
        getSqlMapClientTemplate().update("student.deleteStudentById", stuId);
    }


    @Override
    public void deleteClassStuRelaByStuId(Long stuId) {
        getSqlMapClientTemplate().delete("student.deleteClassStuRelaByStuId", stuId);
    }
}
